
package net.swa.system.web.action;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Required;
import net.swa.system.beans.entity.Dict;
import net.swa.system.service.ICommonService;
import net.swa.system.service.MerchantsTypeService;
import net.swa.system.util.annotation.Log;
import net.swa.util.BuzConst;
import net.swa.util.JsonResult;

/**
 * 字典action
 * 
 * 维护，商家类型数据
 * 
 * @author junyu
 *
 */
public class MerchantsTypeAction extends AbstractBaseAction
{
    private static final long serialVersionUID = -985277678565361630L;

    private Long[] dicIds;

    private Long[] dicNums;

    private Long id;

    private ICommonService commonService;

    private MerchantsTypeService merchantsTypeService;

    private Dict dict;

    /**传入的dict title**/
    private String type;

    /** 字典类型列表 **/
    private List<Dict> typeList;

    /**
    * 列表页面
    * 
    * @return
    */
    @Log(description = "查询商家类型")
    public String listPage() throws Exception
    {
        //        typeList = commonService.search("title", BuzConst.MERCHANTS_TITLE, Dict.class, null, "dictPaixu", "asc");
        return "list";
    }

    /**
     * 编辑、新建操作
     * 
     * @return
     * @throws Exception
     */
    @Log(description = "编辑商家类型")
    public String edit() throws Exception
    {
        if (dict == null)
        {
            dict = new Dict();
        }
        else
        {
            dict = commonService.commonFind(Dict.class, dict.getId());
        }
        dict.setTitle(BuzConst.MERCHANTS_TITLE);
        return "edit";
    }

    /**
     * 保存操作
     * 
     * @return
     * @throws Exception
     */
    public String save() throws Exception
    {
        Map<String, Object> json = merchantsTypeService.addOrUpdate(dict);
        outJson(json);
        return null;
    }

    /**
     * 保存排序
     * 
     * @return
     * @throws Exception
     */
    public String savesort() throws Exception
    {
        Map<String, Object> json = merchantsTypeService.updateDicNum(dicIds, dicNums);
        outJson(json);
        return null;
    }

    public String delete() throws Exception
    {
        Map<String, Object> json = merchantsTypeService.delete(id);
        outJson(json);
        return null;
    }

    public Dict getDict()
    {
        return dict;
    }

    public void setDict(Dict dict)
    {
        this.dict = dict;
    }

    public ICommonService getCommonService()
    {
        return commonService;
    }

    @Resource
    @Required
    public void setCommonService(ICommonService commonService)
    {
        this.commonService = commonService;
    }

    public MerchantsTypeService getMerchantsTypeService()
    {
        return merchantsTypeService;
    }

    @Resource
    @Required
    public void setMerchantsTypeService(MerchantsTypeService merchantsTypeService)
    {
        this.merchantsTypeService = merchantsTypeService;
    }

    public List<Dict> getTypeList()
    {
        return typeList;
    }

    public void setTypeList(List<Dict> typeList)
    {
        this.typeList = typeList;
    }

    public Long[] getDicIds()
    {
        return dicIds;
    }

    public void setDicIds(Long[] dicIds)
    {
        this.dicIds = dicIds;
    }

    public Long[] getDicNums()
    {
        return dicNums;
    }

    public void setDicNums(Long[] dicNums)
    {
        this.dicNums = dicNums;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

}
